package de.rj.urwalking.ui.fragments.dialog;

import de.rj.urwalking.R;
import de.rj.urwalking.ui.activities.QuestionsActivity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

/**
 * Displayed when the user tries to exit the survey.
 * @author rjj
 *
 */
public class CancelSurveyDialog extends DialogFragment implements DialogInterface.OnClickListener {

	public CancelSurveyDialog() {
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());

		alertDialogBuilder.setTitle(getString(R.string.abort_survey));
		alertDialogBuilder.setMessage(getString(R.string.answers_will_be_lost));
		alertDialogBuilder.setPositiveButton(R.string.yes_abort, CancelSurveyDialog.this);
		alertDialogBuilder.setNegativeButton(R.string.no_resume, CancelSurveyDialog.this);

		return alertDialogBuilder.create();
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {

		switch (which) {
		case DialogInterface.BUTTON_NEGATIVE:
			dismiss();
			break;
		case DialogInterface.BUTTON_POSITIVE:
			((QuestionsActivity) getActivity()).abortSurvey();
			break;
		default:
			break;
		}

	}
}